package io.renren.modules.alarm.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.alarm.entity.MachineEntity;
import io.renren.modules.alarm.service.MachineService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author zhourl
 * @email zhou11258@foxmail.com
 * @date 2022-03-06 20:24:38
 */
@RestController
@RequestMapping("alarm/machine")
@Api("设备接口")
public class MachineController {
    @Autowired
    private MachineService machineService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @RequiresPermissions("alarm:machine:list")
    @ApiOperation("设备列表")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = machineService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @ApiOperation("设备信息")
    @GetMapping("/info/{machId}")
    @RequiresPermissions("alarm:machine:info")
    public R info(@PathVariable("machId") Long machId) throws ParseException {
		MachineEntity machine = machineService.getById(machId);
        return R.ok().put("machine", machine);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @RequiresPermissions("alarm:machine:save")
    public R save(@RequestBody MachineEntity machine){
		machineService.save(machine);

        return R.ok();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @RequiresPermissions("alarm:machine:update")
    public R update(@RequestBody MachineEntity machine){
		machineService.updateById(machine);

        return R.ok();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @RequiresPermissions("alarm:machine:delete")
    public R delete(@RequestBody Long[] machIds){
		machineService.removeByIds(Arrays.asList(machIds));

        return R.ok();
    }

}
